import Vue from 'vue';
import App from './App';
import request from './utils/request.js'
// import uploadFile from './utils/uploadFile'
import uView from 'uview-ui';
import md5 from "./uview-ui/libs/function/md5"
import store from './store'

import share from '@/common/share.js'


// 弹出框
import DialogBox from './components/DialogBox/DialogBox';
import DialogBox0 from './components/DialogBox/DialogBox0';

import {
    selectDictLabel
} from "@/utils/common";
Vue.prototype.formatDate = function (t) {
    t = t || Date.now();
    let time = new Date(t);
    let str = time.getMonth() < 9 ? ('0' + (time.getMonth() + 1)) : (time.getMonth() + 1);
    str += '-';
    str += time.getDate() < 10 ? ('0' + time.getDate()) : time.getDate();
    str += ' ';
    str += time.getHours();
    str += ':';
    str += time.getMinutes() < 10 ? ('0' + time.getMinutes()) : time.getMinutes();
    return str;
}

// 封装的uni-api
import {
    message,
    loading,
    hideLoading,
    navigateTo,
    redirectTo,
    navigateBack,
    reLaunch
} from './utils/uni-api.js'
import {
    judgeLogin,
    judgeLogin0
} from '@/common/login.js';
Vue.prototype.judgeLogin = judgeLogin;
Vue.prototype.judgeLogin0 = judgeLogin0;
// #ifdef APP
// 自定义showModal组件
import f_show_modal from '@/components/module/show_modal/f_show_modal.js'
Vue.use(f_show_modal)
// #endif
Vue.prototype.$message = message
Vue.prototype.$loading = loading
Vue.prototype.$hideLoading = hideLoading
Vue.prototype.$navigateTo = navigateTo
Vue.prototype.$redirectTo = redirectTo
Vue.prototype.$navigateBack = navigateBack
Vue.prototype.$reLaunch = reLaunch
Vue.prototype.$request = request
Vue.prototype.$bus = new Vue()
// Vue.prototype.$uploadFile = uploadFile
Vue.prototype.$md5 = md5
// Vue.prototype.$name = '';
Vue.prototype.$imgUrl = 'https://yl.weilankangyang.com/static/mini_program/' //存放静态图片地址URL

Vue.prototype.$movieApi = 'https://movie.guoqushengxian.com/' 
Vue.prototype.selectDictLabel = selectDictLabel

Vue.config.productionTip = false

import publicModule from "@/components/common/public-module.vue";
Vue.component("public-module", publicModule);
// 全局组件
Vue.component('DialogBox', DialogBox);
Vue.component('DialogBox0', DialogBox0);

Vue.use(uView);


Vue.mixin(share)
Vue.mixin({
    methods: {
        setData: function (obj, callback) {
            let that = this;
            let keys = [];
            let val, data;
            Object.keys(obj).forEach(function (key) {
                keys = key.split('.');
                val = obj[key];
                data = that.$data;
                keys.forEach(function (key2, index) {
                    if (index + 1 == keys.length) {
                        that.$set(data, key2, val);
                    } else {
                        if (!data[key2]) {
                            that.$set(data, key2, {});
                        }
                    }
                    data = data[key2];
                })
            });
            callback && callback();
        }
    }
})

App.mpType = 'app'

const app = new Vue({
    store,
    ...App
})
app.$mount()